<template>
  <div class="container">
    <div>
      <el-row :gutter="20">
        <el-col :span="6">
          <el-form ref="form" :model="form">
            <el-form-item label="开始日期：">
              <el-date-picker
                v-model="form.StartDate"
                type="date"
                placeholder="选择日期"
                value-format="yyyy-MM-dd"
              ></el-date-picker>
            </el-form-item>
          </el-form>
        </el-col>
        <el-col :span="6">
          <el-form ref="form" :model="form">
            <el-form-item label="结束日期：">
              <el-date-picker
                v-model="form.EndDate"
                type="date"
                placeholder="选择日期"
                value-format="yyyy-MM-dd"
              ></el-date-picker>
            </el-form-item>
          </el-form>
        </el-col>
        <el-col :span="6">
          <el-form ref="form" :model="form">
            <el-form-item label="转运站：">
              <el-select v-model="form.place" placeholder="请选择">
                <el-option
                  v-for="item in form.placeList"
                  :key="item.index"
                  :label="item.NAME"
                  :value="item.ID"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-form>
        </el-col>
        <el-col :span="4">
          <el-form ref="form" :model="form" style="float: left">
            <el-button size="mini" type="primary" @click="getlistdata"
              >查 询</el-button
            >
            <el-button size="mini" type="success" @click="exportExcel"
              >导 出</el-button
            >
          </el-form>
        </el-col>
      </el-row>
    </div>
    <el-table
      highlight-current-row
      v-loading="loading"
      :data="
        tableData.slice((currentPage - 1) * pageSize, currentPage * pageSize)
      "
    >
      <el-table-column
        prop="转运站名称"
        label="转运站"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="称重总吨数"
        label="称重总吨数"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="日期"
        label="称重日期"
        align="center"
      ></el-table-column>
      <el-table-column label="操作" width="100">
        <template slot-scope="scope">
          <el-button
            type="text"
            v-if="scope.row.日期 !== '合计'"
            @click="handleEdit(scope.$index, scope.row)"
            >详情</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    
    <div class="pagination">
      <el-pagination
        background
        layout="total, sizes, prev, pager, next, jumper"
        :current-page="currentPage"
        :page-size="pageSize"
        :total="tableData.length"
        @size-change="handleSizeChange"
        @current-change="handlePageChange"
      ></el-pagination>
    </div>
    <!-- 称重详情列表 -->
    <el-dialog title="转运站称重详情信息" :visible.sync="editVisible" modal="false" width="50%">
      <el-table :data="tableDataDetail" height="500">
        <el-table-column prop="车牌号" label="车牌号"></el-table-column>
        <el-table-column prop="称重吨数" label="称重吨数"></el-table-column>
        <el-table-column prop="垃圾类型" label="垃圾类型"></el-table-column>
        <el-table-column prop="称重时间" label="称重时间"></el-table-column>
      </el-table>
    </el-dialog>
  </div>
</template>
<script>
import '@/assets/css/common.css'
import { formatDate } from '@/common/js/date.js'
import export2Excel from '@/utils/exportExcel/index.js'
export default {
  data () {
    return {
      currentPage: 1, //初始页
      pageSize: 10,    //    每页的数据
      loading: false,
      form: {
        StartDate: formatDate(new Date(new Date() - 3600 * 1000 * 24), 'yyyy-MM-dd'),
        EndDate: formatDate(new Date(), 'yyyy-MM-dd'),
        placeList: [],//转运站列表
        place: '0',
      },
      // teamList: [{ "CLIENT_NAME": "机扫车" }, { "CLIENT_NAME": "垃圾车" }],
      // teamValue: '机扫车',
      editVisible:false,
      tableData: [],
      tableDataDetail: [],
      originalData: []
    }
  },
  created () {
    this.getPlaceStationList()
    this.getlistdata()
  },
  methods: {
    async getlistdata () {
      this.currentPage = 1;
      this.loading = true
      var url = 'RubbishVehicle/GetRubbishDBAll?StartDate=' + this.form.StartDate + '&EndDate=' + this.form.EndDate + '&ClientNo=' + localStorage.getItem('CLIENT_NO') + '&ID=' + this.form.place
      const { data } = await this.$Http.get(url)
      this.tableData = data
      this.loading = false
    },
    //获取转运站列表
    async getPlaceStationList () {
      var url = '/RubbishVehicle/GetPlaceStationSelectList?ClientNo=' + localStorage.getItem('CLIENT_NO')
      const { data } = await this.$Http.get(url)
      this.form.placeList = data
    },
    //获取转运站称重详情列表
    async getRubbishDetailList () {
      var url = '/RubbishVehicle/GetRubbishDBAllDetail?Date=' + this.form.日期 + '&ID=' + this.form.PARENT_ID
      const { data } = await this.$Http.get(url)
      this.tableDataDetail = data
    },
    
    // 导出Excel
    exportExcel () {
      let excelName = '地磅称重统计'
      const tHeader = ['转运站', '车牌号', '称重时间', '毛重', '皮重', '净重', '垃圾类型', '发货单位']
      const filterVal = ['转运站', '车牌号', '称重时间', '毛重', '皮重', '净重', '垃圾类型', '发货单位']
      export2Excel(tHeader, filterVal, this.tableData, excelName)
    },
    //详情
    handleEdit (index, row) {
      this.form = Object.assign({}, row);
      this.editVisible = true;
      this.getRubbishDetailList()
    },
    // 分页导航
    handlePageChange (currentPage) {
      this.currentPage = currentPage;
      // console.log(this.currentPage)
      // this.$set(this.query, 'pageIndex', val);
      // this.getData();
    },
    handleSizeChange (size) {
      this.pageSize = size;
      console.log(this.pageSize)
    }
  }
}
</script>
<style>
.content {
  overflow-y: scroll;
}
.el-col-6 {
  min-width: 400px;
  min-height: 50px;
}
.el-table th {
  height: 40px;
}
</style>